<?php
require_once __DIR__ . '/../functions.php';

header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $input = json_decode(file_get_contents('php://input'), true);
    
    $themeName = $input['theme_name'] ?? 'sakura';
    $themeColor = $input['theme_color'] ?? DEFAULT_THEME_COLOR;
    
    // 验证主题是否存在
    if (!array_key_exists($themeName, THEME_COLORS)) {
        echo json_encode(['success' => false, 'message' => '无效的主题']);
        exit;
    }
    
    // 更新主题
    updateUserTheme($themeName, $themeColor);
    
    echo json_encode(['success' => true, 'message' => '主题更新成功']);
} else {
    echo json_encode(['success' => false, 'message' => '无效的请求方法']);
}